package jroguelike.main;

import aimozg.joglfw.GLColor;
import jroguelike.main.proto.ItemProtos;

/**
 * Created by IntelliJ IDEA.
 * User: aimozg
 * Date: 31.07.11
 * Time: 19:28
 */
public class RLItem {

	////////////// CORE PROPERTIES

	/**
	 * ItemClass of this item. No way it could be changed.
	 */
	public final ItemClass clazz;
	/**
	 * A displayable name of the item
	 */
	public String name = "";
	// TODO durability
	// TODO quantity
	// TODO price
	// TODO quality (irradiated/normal/clean/old/new)

	///////////// WORLD-RELATED

	public String displayName() {
		return name;
	}

	/**
	 * Glyph used to display character on map
	 */
	public char glyph = ItemProtos.DEFAULT_CHAR_MISC;
	public GLColor color = GLColor.WHITE;
	public RLMap map = null;
	public int xy;

	public void moveTo(RLMap map, int xy) {
		if (this.map != null) this.map.notifyItemMovedOut(this, this.xy);
		this.map = map;
		if (map != null) {
			this.xy = xy;
			map.notifyItemMovedIn(this, this.xy);
		}
	}

	public void moveTo(RLMap map, int x, int y) {
		moveTo(map, (map == null) ? 0 : map.xy(x, y));
	}

	///////////// METHODS


	public RLItem(ItemClass clazz) {
		this.clazz = clazz;
	}

	protected void copyTo(RLItem other) {
		other.name = name;
		other.glyph = glyph;
		other.color = color;
	}

	/**
	 * Creates a duplicate of the item, having the same item-related properties, but owner and level being null. The copy
	 * should be placed somewhere by caller
	 */
	public RLItem makeClone() {
		RLItem other = new RLItem(this.clazz);
		copyTo(other);
		return other;
	}


	@Override
	public String toString() {
		return String.format("Item[%s]", displayName());
	}
}
